package com.gao.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author gao
 * @time 2022/11/25 11:12:31
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultVO {
    private Integer code;
    private String msg;
    private Object data;

    public ResultVO(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private ResultVO(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }

    private ResultVO(ResultCode resultCode, Object data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    public static ResultVO success() {
        return success(ResultCode.SUCCESS);
    }

    public static ResultVO success(String msg) {
        return new ResultVO(ResultCode.SUCCESS.getCode(), msg);
    }

    public static ResultVO success(Object data) {
        return new ResultVO(ResultCode.SUCCESS, data);
    }

    public static ResultVO success(String msg, Object data) {
        return new ResultVO(ResultCode.SUCCESS.getCode(), msg, data);
    }

    public static ResultVO failure() {
        return failure(ResultCode.FAILURE);
    }

    public static ResultVO failure(String msg) {
        return new ResultVO(ResultCode.FAILURE.getCode(), msg);
    }

    public static ResultVO failure(Object data) {
        return new ResultVO(ResultCode.FAILURE, data);
    }

    public static ResultVO failure(String msg, Object data) {
        return new ResultVO(ResultCode.FAILURE.getCode(), msg, data);
    }
}
